package com.lantu.sys.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lantu.common.vo.RResult;
import com.lantu.sys.entity.Student;
import com.lantu.sys.entity.Teacher;
import com.lantu.sys.mapper.TeacherMapper;
import com.lantu.sys.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/teacher")
@CrossOrigin
@Slf4j
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    TeacherMapper teacherMapper;
    //获取教师信息用户列表
    @GetMapping("/getTeachers/{pageNo}/{pageSize}")
    public RResult getTeachers(
             @PathVariable("pageNo") Integer pageNo ,
             @PathVariable("pageSize") Integer pageSize ,
            Teacher teacher
    ){
        Page<Teacher> paraParam =new Page<>(pageNo,pageSize);

        IPage<Teacher> page = teacherService.getTeachersByOpr(paraParam,teacher);

        return RResult.ok(page);
    }
    //增加或者修改教师信息
    @PostMapping("/saveOrUpdateTeacher")
    public RResult saveOrUpdateTeacher(
             @RequestBody Teacher teacher
    ){
        teacherService.saveOrUpdate(teacher);
        return  RResult.ok();
    }
    //表格回显
    @GetMapping("/getById/{tno}")
    public RResult<Teacher> getUid(@PathVariable("tno") Integer tno){
        Teacher byId = teacherService.getByTeacherById(tno);
        return RResult.ok(byId);
    }
    //根据id进行删除
    @DeleteMapping("/{id}")
    public RResult delStudentById(@PathVariable Integer id
    ){
        teacherService.removeById(id);
        return RResult.ok();
    }

    //统计所有教师人数
    @GetMapping("/count/teacher")
    public List<Map<String,Object>> getAllTeacher(){

        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.eq("zhicheng","正高级教师");
        long count01 = teacherService.count(teacherQueryWrapper);

        QueryWrapper<Teacher> teacherQueryWrapper01 = new QueryWrapper<>();
        teacherQueryWrapper01.eq("zhicheng","无职称");
        long count02 = teacherService.count(teacherQueryWrapper01);

        QueryWrapper<Teacher> teacherQueryWrapper02 = new QueryWrapper<>();
        teacherQueryWrapper02.eq("zhicheng","高级教师");
        long count03 = teacherService.count(teacherQueryWrapper02);

        QueryWrapper<Teacher> teacherQueryWrapper04 = new QueryWrapper<>();
        teacherQueryWrapper04.eq("zhicheng","一级教师");
        long count04 = teacherService.count(teacherQueryWrapper04);

        QueryWrapper<Teacher> teacherQueryWrapper05 = new QueryWrapper<>();
        teacherQueryWrapper05.eq("zhicheng","二级教师");
        long count05 = teacherService.count(teacherQueryWrapper05);

        QueryWrapper<Teacher> teacherQueryWrapper06 = new QueryWrapper<>();
        teacherQueryWrapper06.eq("zhicheng","三级教师");
        long count06 = teacherService.count(teacherQueryWrapper06);

        List<Long> list01 =new ArrayList<>();
        list01.add(count01);
        list01.add(count02);
        list01.add(count03);
        list01.add(count04);
        list01.add(count05);
        list01.add(count06);

        List<String> list02 = new ArrayList<>();
        list02.add("正高级教师");
        list02.add("无职称");
        list02.add("高级教师");
        list02.add("一级教师");
        list02.add("二级教师");
        list02.add("三级教师");

        List<Map<String,Object>> Counst = new ArrayList<>();
        for (int i = 0; i < list01.size(); i++) {
            Map<String,Object> map =new HashMap<>();
            map.put("zhicheng",list02.get(i));
            map.put("num",list01.get(i));
            Counst.add(map);
        }
        return Counst;

    }
    //获取动态职称下拉菜单
    @GetMapping("/xialacaidan")
    public List<Map<String,Object>> getXiala(){
        List<Teacher> getzhicheng = teacherService.getlist();
        Set<Map<String,Object>> ll = new HashSet<>();
        int i =2;
        for (Teacher zc: getzhicheng) {
            Map<String,Object> map =new HashMap<>();
            if(zc==null){
                map.put("label","无职称");
                map.put("value","无职称");
            }else{
                map.put("label",zc.getZhicheng());
                map.put("value",zc.getZhicheng());
            }
            ll.add(map);
        }
        List<Map<String,Object>> list = new ArrayList<>(ll);
        return list;
    }

    //统计所有教师人数
    @GetMapping("/countallteacher")
    public RResult getallcount(){
        QueryWrapper<Teacher> studentQueryWrapper = new QueryWrapper<>();
        studentQueryWrapper.select("count(*)as teachernum");
        Teacher one = teacherService.getOne(studentQueryWrapper);
        System.out.println(one);
        return RResult.ok(one);

    }


}
